<%-- 
    Document   : V_PersonaEmail_Update
    Created on : 12-nov-2014, 23:35:29
    Author     : JoseHernan
--%>
<%@page import="java.util.ArrayList"%>
<%@page import="beans.B_PersonaEmail"%>
<%@page import="db.DB_PersonaEmail"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%

    if (session.getAttribute("userName") != null) {
        String userName = session.getAttribute("userName").toString();
        session.setAttribute("userName", userName);
        //NEW OR UPDATE
        String action = request.getParameter("action").toString();
        String idPersona = request.getParameter("idPersona").toString();
        B_PersonaEmail obj;
        int id = 0;
        if (action.equals("u")) {
            id = Integer.parseInt(request.getParameter("id").toString());
            ArrayList<B_PersonaEmail> list = DB_PersonaEmail.getList(id);
            obj = list.get(0);
        } else {
            obj = new B_PersonaEmail();
        }
%>
<!-- BEGIN PAGE LEVEL STYLES -->
<!-- END PAGE LEVEL SCRIPTS -->
<!-- BEGIN FORM-->
<form id="form_xsis_2" name="form_xsis_2" class="form-horizontal" style="width: 500px;">
    <div class="modal-header">
        <button id="closeModal1" type="button" class="close close2" data-dismiss="modal" aria-hidden="true"></button>
        <h4 class="modal-title">Email</h4>
    </div>
    <div class="modal-body">
        <div class="row">
            <div class="col-md-12">
                <div class="form-body">
                    <div class="alert alert-danger display-hide">
                        <button class="close" data-close="alert"></button>
                        <label id="messageReturn2"></label>
                    </div>                   
                    <div class="form-group">
                        <label class="control-label col-md-3">Email: <span class="required"> * </span>
                        </label>
                        <div class="col-md-9">
                            <div class="input-group">
                                <span class="input-group-addon">
                                    <i class="fa fa-envelope"></i>
                                </span>
                                <input name="email" id="email" type="text" class="form-control" placeholder="Email" value="<%= obj.getEmail()%>">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button id="closeModal2" type="button" class="btn default" data-dismiss="modal">Cerrar</button>
        <button id="save2" type="submit" class="btn blue">Guardar</button>
    </div>
    <input type="hidden" name="action2" value="<%= action%>">
    <input type="hidden" name="id2" value="<%= id%>">
    <input type="hidden" name="idPersona" value="<%= idPersona%>">
</form>
<!-- END FORM-->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script>
    function valid() {
        var correcto = true;
        $(".errorMessage").remove();
        if ($("#email").val() === "") {
            $("#email").parent().parent().append("<span class='errorMessage'>Ingrese email.</span>");
            correcto = false;
        }
        if (correcto === true) {
            if ($("#email").val().indexOf('@', 0) === -1 || $("#email").val().indexOf('.', 0) === -1) {
                $("#email").parent().parent().append("<span class='errorMessage'>Email incorrecto.</span>");
                correcto = false;
            }
        }
        return correcto;
    }
</script>
<script>
    $('#save2').click(function () {
        if (!valid()) {
            return false;
        }
        sendDataForm2Update1('C_PersonaEmail', '#table_content'); // submit the form
        return false;
    });
</script>
<script>
    $('#form_xsis_2').keypress(function (event) {
        if (event.which === 13) {
            if (!valid()) {
                return false;
            }
            sendDataForm2Update1('C_PersonaEmail', '#table_content'); // submit the form
            return false;
        }
    });
</script>
<!-- END PAGE LEVEL SCRIPTS -->

<% } else {

        out.print("<script language='Javascript'>"
                + "alert('Su sessión a expirado, ingrese nuevamente.');"
                + "window.location.href = 'index.jsp'"
                + "</script>");
    }%>